﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SpriteClasses;

namespace FrostFights
{
    public class Meter
    {
        public Texture2D meterTexture;
        public Texture2D meterBacking;
        public Vector2 position;
        public Vector2 backingPosition;
        public Rectangle meterRect;
        public ContentManager Content;

        public Meter(ContentManager _content, Player player) //Add position vector for X and Y of meter if you plan to have multiple meters.
        {
            Content = _content;
            meterTexture = Content.Load<Texture2D>("Images/healthbarinside");
            meterBacking = Content.Load<Texture2D>("Images/healthbar");
            position = new Vector2(player.Position.X - 40, player.Position.Y + 20);
            backingPosition.X = position.X - 1;
            backingPosition.Y = position.Y - 1;
            meterRect = new Rectangle(0, 0, meterTexture.Width, meterTexture.Height);
        }

        public void MoveMeter(GameTime gameTime, Player player)
        {
            position = new Vector2(player.Position.X - 38, player.Position.Y + 80);
            backingPosition.X = position.X - 1;
            backingPosition.Y = position.Y - 1;
        }

        public void Update(Player player)
        {
            meterRect.Width = (int)(meterTexture.Width * (player.Health / player.MaxHealth));
        }

        public void DrawMeter(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(meterBacking, backingPosition, Color.White);       //Stationary meter
            spriteBatch.Draw(meterTexture, position, meterRect, Color.White);   //Moving meter
        }

        public void ChangeTexture(String imageName)
        {
            meterTexture = Content.Load<Texture2D>("Images/" + imageName);
        }
    }
}
